"""
遍历列表，取出偶数，存入新的列表中
分别使用while和for实现
"""

def func_while(data):
    result = []
    index = 0
    while index < len(data):
        element = number[index]
        if element % 2 == 0:
            result.append(element)
            num = 400
        index += 1
    return result

def func_for(data):
    result = []
    for element in data:
        if element % 2 == 0:
            result.append(element)
    return result

number = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
# result = func_while(number)
result = func_for(number)
print(result) # [2, 4, 6, 8, 10]